import winston from 'winston'
require('winston-daily-rotate-file');

const logFileTransport = new (winston.transports.DailyRotateFile)({
    filename: './log/application-%DATE%.log',
    datePattern: 'YYYY-MM-DD-HH',
    zippedArchive: true,
    maxSize: '20m',
    maxFiles: '14d'
});
const logger = new winston.Logger({
    level: 'info',
    transports: [
        new (winston.transports.Console)({ colorize: true }),
        // logFileTransport,//存储日志文件

    ]
});
//查询日志
/*const options = {
    from: new Date - 24 * 60 * 60 * 1000,
    until: new Date,
    limit: 10,
    start: 0,
    order: 'desc',
    fields: ['message']
};


// 查找在今天和昨天之间记录的项目
winston.query(options, function (err, results) {

});*/
export const info = msg => logger.info(msg);
export const debug = msg => logger.debug(msg);
export const error = msg => logger.error(msg);
export const warn = msg => logger.warn(msg);

export default logger;
